home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / DVIEW030.LZH / VIEWDRAW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-09  |  5.9 KB  |  289 lines

  1. #define C
  2.  
  3. #undef PROFILE
  4. #define COUNT
  5.  
  6. #include "view.h"
  7. #include "trig.h"
  8.  
  9. #ifdef __GNUC__
  10.   #include <osbind.h>
  11.   #include <memory.h>
  12. #else
  13.   #include <tos.h>
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.             
  20. #define SKY_COLOR       1
  21. #define FLOOR_COLOR     2
  22. #define WALL_COLOR      3
  23. #define RED_COLOR       4
  24. #define LEDGE_COLOR     5
  25. #define ZMIN            20L  
  26.  
  27. #define UPPER_TYPE      0
  28. #define WALL_TYPE       1
  29. #define LOWER_TYPE      2
  30.  
  31. extern short width;
  32. extern short height;
  33.  
  34. extern short flooropt;
  35. extern short floorcol;
  36. extern short nofloor;
  37. extern short wallopt;
  38. extern short wallcol;
  39. extern short singlestep;
  40. extern short showdata;
  41.  
  42. #ifdef COUNT
  43. extern long drawview;
  44.  
  45. extern long addfloor;
  46. extern long addfloor_loops;
  47.  
  48. extern long addwall;
  49. extern long addwall_loops;
  50.  
  51. extern long coldraw;
  52. extern long coldraw_loops;
  53.  
  54. extern long rowdraw;
  55. extern long rowdraw_loops;
  56.  
  57. extern long drawnode;
  58. extern long drawssector;
  59. extern long drawssector_loops;
  60. extern long loadseg;
  61. extern long loadseg_loops1;
  62. extern long loadseg_loops2;
  63.  
  64. extern long setuptime;
  65. extern long drawtime;
  66. extern long c2ptime;
  67. #endif
  68.  
  69. /* Elements of this array indicate if a screen column is completely drawn. */
  70.  
  71. #if 0
  72. extern short     Col_Done[320];
  73. #endif
  74. extern char      Col_Done[320];    /* Slightly better for the cache */
  75.  
  76.  
  77. /* Elements of this array hold indexes into the wall_run array. */
  78.  
  79. #if 1
  80. extern short     intersections[50][320];
  81. #endif
  82.  
  83. /* The number of wall_runs visible on a particular screen column. */
  84.  
  85. #if 1
  86. extern short     int_count[320];
  87. #endif
  88.  
  89. /* MaxY & MinY are the active edge lists for the top & bottom of the screen. */
  90.  
  91. extern short     MaxY[320];
  92. extern short     MinY[320];
  93.  
  94.  
  95. /* This is the wall_run array.  It contains all of the wall_runs which
  96.  * are visible in a single frame.
  97.  */
  98.  
  99. #if 1
  100. extern wall_run  walls[8000];  /* 320*50 = 16000 */
  101. #endif
  102.  
  103. extern short walltop[320];
  104. extern short wallbottom[320];
  105.  
  106. /* The next two arrays are used for both floors and ceilings.
  107.  * Elements of this array hold indexes into the floor_run array.
  108.  */
  109.  
  110. #if 1
  111. extern floor_run floorlist[200][40];
  112. #endif
  113.  
  114. extern short floorlst[200];
  115. extern short floortex[200];
  116.  
  117. /* The number of floor_runs visible on a particular screen column. */
  118.  
  119. extern short     runcount[200];
  120.  
  121.  
  122. /* The offscreen buffer. */
  123. extern char *screenbuf;
  124.  
  125.  
  126. extern void c2p(char *buf, int w_area, int h_area);
  127. extern char hash(side *ThisSide, int wall_type);
  128. extern long get_timer(void);
  129.  
  130. /* This function draws a single color column into the
  131.  * offscreen buffer.
  132.  */
  133.  
  134. void ColDraw(short x, short top, short bottom, char color)
  135. {
  136.    short y;
  137.    char *pixel;
  138.  
  139.    if (top < 0)
  140.       top = 0;
  141.  
  142.    if (bottom > height)
  143.       bottom = height;
  144.  
  145. #ifdef COUNT
  146.    coldraw++;
  147.    coldraw_loops += bottom - top;
  148. #endif
  149.  
  150. #ifdef __GNUC__
  151. #if 0
  152.    pixel = &screenbuf[(long)((top << 6) + (top << 8)) + x];
  153. #else
  154.    pixel = &screenbuf[(long)top * width + x];
  155. #endif
  156. #else
  157. #if 0
  158.    pixel = &(((short *)screenbuf)[(((long)top << 6) + ((long)top << 8)) >> 1]);
  159. #else
  160.    pixel = &(((short *)screenbuf)[((long)top * width) >> 1]);
  161. #endif
  162.    pixel += x;
  163. #endif
  164. #if 0
  165.    for (short y = top;y < bottom;y++) {
  166. #endif
  167.    for(y = bottom - top - 1;y >= 0;y--) {
  168.       *pixel = color;
  169.       pixel += width;
  170.    }
  171. }
  172.  
  173.  
  174. /* This function draws a single color row into the
  175.  * offscreen buffer.
  176.  */
  177.  
  178. void RowDraw(short y, short left, short right, char color)
  179. {
  180.    short x;
  181.    char *pixel;
  182.  
  183.    if (left < 0)
  184.       left = 0;
  185.  
  186.    if (right > width)
  187.       right = width;
  188.  
  189. #ifdef COUNT
  190.    rowdraw++;
  191.    rowdraw_loops += right - left;
  192. #endif
  193.  
  194. #ifdef __GNUC__
  195. #if 0
  196.    pixel = &screenbuf[(long)((y << 6) + (y << 8)) + left];
  197. #else
  198.    pixel = &screenbuf[(long)y * width + left];
  199. #endif
  200. #else
  201. #if 0
  202.    pixel = &(((short *)screenbuf)[(((long)y << 6) + ((long)y << 8)) >> 1]);
  203. #else
  204.    pixel = &(((short *)screenbuf)[((long)y * width) >> 1]);
  205. #endif
  206.    pixel += left;
  207. #endif
  208. #if 0
  209.    for (short x = left;x < right;x++) {
  210. #endif
  211.    for(x = right - left - 1;x >= 0;x--) {
  212. if (!singlestep) {
  213.       *pixel = color;
  214. } else {
  215.       *pixel ^= color;     /* EXOR */
  216. }
  217.       pixel++;
  218.    }
  219. }
  220.  
  221. /* Here is where we blast all of the runs to the screen buffer. */
  222.  
  223. void DrawSegs(void)
  224. {
  225.    short row;
  226.    char ch = 0;
  227.    short run;
  228.    short x, i;
  229.    short Wall;
  230.    wall_run *ThisWallRun;
  231.  
  232. #if 0
  233. if (nofloor && !flooropt) {
  234.    memset(screenbuf, 0, (long)width * height);
  235. }
  236. #endif
  237.  
  238. if (!flooropt && !nofloor) {
  239.    for(row = 0;row < height / 2;row++) {
  240.       for(run = 0;run < runcount[row];run++) {
  241.   if (!floorcol) {
  242.          RowDraw(row, floorlist[row][run].start,
  243.                  floorlist[row][run].end, SKY_COLOR);
  244.   } else {
  245.          RowDraw(row, floorlist[row][run].start,
  246.                  floorlist[row][run].end, floorlist[row][run].tex_num);
  247.   }
  248. if (singlestep && (ch != 's')) {
  249.    c2p(screenbuf, width, height);
  250.    ch = Cnecin();
  251. }
  252.       }
  253. if (singlestep) {
  254.    c2p(screenbuf, width, height);
  255.    ch = Cnecin();
  256. }
  257.    }
  258.  
  259.    for (row = height / 2;row < height;row++) {
  260.       for(run = 0;run < runcount[row];run++) {
  261.   if (!floorcol) {
  262.          RowDraw(row, floorlist[row][run].start,
  263.                  floorlist[row][run].end, FLOOR_COLOR);
  264.   } else {
  265.          RowDraw(row, floorlist[row][run].start,
  266.                  floorlist[row][run].end, floorlist[row][run].tex_num);
  267.   }
  268. }
  269. if (singlestep && (ch != 's')) {
  270.    c2p(screenbuf, width, height);
  271.    ch = Cnecin();
  272. }
  273.       }
  274. if (singlestep) {
  275.    c2p(screenbuf, width, height);
  276.    ch = Cnecin();
  277. }
  278.    }
  279. if (!wallopt) {
  280.    for(x = 0;x < width;x++)
  281.       for(i = 0;i < int_count[x];i++) {
  282.          Wall = intersections[i][x];
  283.          ThisWallRun = &walls[Wall];
  284.          ColDraw(x, ThisWallRun->top, ThisWallRun->bottom,
  285.                  (char)ThisWallRun->tex_num);
  286.       }
  287. }
  288. }
  289.